﻿using System;
using System.Collections.Generic;
using System.Linq;
using Autodesk.Revit.DB;

namespace YJKRevitDimensionText.DoorWindowDim
{
	public class DimensionStyleManager
	{
		private static void GetCurDocAllDimStyleType(Autodesk.Revit.DB.Document doc)
		{
			if (0 < DimensionStyleManager.m_dictDimStyleToDimType.Count)
			{
				DimensionStyleManager.m_dictDimStyleToDimType.Clear();
			}
			foreach (ElementId elementId in new FilteredElementCollector(doc).OfClass(typeof(DimensionType)).ToElementIds().ToList<ElementId>())
			{
				DimensionType dimensionType = doc.GetElement(elementId) as DimensionType;
				if (dimensionType != null)
				{
					DimensionStyleType styleType = dimensionType.StyleType;
					if (dimensionType.ParametersMap != null && dimensionType.ParametersMap.Size != 0)
					{
						if (!DimensionStyleManager.m_dictDimStyleToDimType.ContainsKey(styleType))
						{
							List<DimensionType> list = new List<DimensionType>();
							list.Add(dimensionType);
							DimensionStyleManager.m_dictDimStyleToDimType.Add(styleType, list);
						}
						else
						{
							DimensionStyleManager.m_dictDimStyleToDimType[styleType].Add(dimensionType);
						}
					}
				}
			}
		}

		public static List<DimensionType> GetDimensionTypeByStyleType(DimensionStyleType dimStyleType, Autodesk.Revit.DB.Document doc)
		{
			DimensionStyleManager.GetCurDocAllDimStyleType(doc);
			return DimensionStyleManager.m_dictDimStyleToDimType[dimStyleType];
		}

		private static Dictionary<DimensionStyleType, List<DimensionType>> m_dictDimStyleToDimType = new Dictionary<DimensionStyleType, List<DimensionType>>();
	}
}
